'use strict';

/**
 * The label factory provides a label entry. For the label text
 * it expects either a string provided by the options.labelText
 * parameter or it could be generated programmatically using a
 * function passed as the options.get parameter.
 *
 * @param  {Object} options
 * @param  {string} options.id
 * @param  {string} [options.labelText]
 * @param  {Function} [options.get]
 * @param  {Function} [options.showLabel]
 * @param  {Boolean} [options.divider] adds a divider at the top of the label if true; default: false
 */
var label = function (options) {
    return {
        id: options.id,
        html: '<label data-value="label" ' +
        'data-show="showLabel" ' +
        'class="entry-label' + (options.divider ? ' divider' : '') + '">' +
        '</label>',
        get: function (element, node) {
            if (typeof options.get === 'function') {
                return options.get(element, node);
            }
            return {label: options.labelText};
        },
        showLabel: function (element, node) {
            if (typeof options.showLabel === 'function') {
                return options.showLabel(element, node);
            }
            return true;
        }
    };
};

module.exports = label;
